***HORMONAL CONTRACEPTION AND ANEMIA ANALYSIS
***REPLICATION DO-FILE

***David Canning and Mahesh Karra
***VERSION: 1-22-26

***STEP 0: SETTING WORKING DIRECTORY
***To set the correct file directory, replace "SET WORKING DIRECTORY" with the appropriate file path under which your replications files are stored.

***ADDITIONAL PACKAGES NEEDED
*estout
*outreg2

version 13

global maindir "SET WORKING DIRECTORY"

***OPEN REPLICATION DATASET
use "$maindir\REPLICATION_DATA.dta", clear

***OUTPUTS STORED IN maindir
cd "$maindir"

***DESCRIPTIVE STATISTICS AND TABULATIONS

***TABLE 1: DESCRIPTIVE BY WAVE
*OUTCOMES
forvalues x = 2016/2018 {
estpost sum hem hem_preg_adj anemia_* if year==`x'
esttab using Table1_`x'_Descriptive_Outcomes.rtf, cells("mean(fmt(3)) sd(fmt(3)) min(fmt(1)) max(fmt(1))") nomtitle nonumber replace

*TREATMENT AND COVARIATES
estpost sum treatment pregnow curr_use curr_method_use_* hormonal educ_* work own_ag_land age tot_children bmi if year==`x'
esttab using Table1_`x'_Descriptive_Covariates.rtf, cells("mean(fmt(3)) sd(fmt(3)) min(fmt(1)) max(fmt(1))") nomtitle nonumber replace
}

***FIGURE 1: HISTOGRAMS OF HEMOGLOBIN
twoway hist hem_preg_adj if year==2016, freq color(gs12) lcolor(white) || hist hem_preg_adj if year==2018, freq color(none) lcolor(black) title("Histograms of Hemoglobin Levels by Year") xtitle("Hemoglobin (g/cL)") legend(label(1 "2016") label(2 "2018"))
graph export Figure_1.png, replace
graph export Figure_1.svg, replace
gr export Figure_1.eps, as(eps) preview(off) replace
!epstopdf Figure_1.eps

***TABLE: HEMOGLOBIN LEVELS AND ANEMIA STATUS BY METHOD USED, WAVE 3
estpost tab anemia_dum curr_method_use if year==2018
esttab using Table_Desc.rtf, cells("b(label(freq)) colpct(fmt(2)) cumpct(fmt(2))") varlabels(`e(labels)') nonumber nomtitle noobs replace

***CROSS-SECTION AND PANEL REGRESSIONS

*TABLE 2 COL 1: CROSS-SECTIONAL W3 REGRESSION

global covariates "work own_ag_land bmi i.educ ever_use i.age tot_children i.area"

reg hem pregnow i.curr_method_use if year==2018, robust
outreg2 using Table_2_1.doc, ci replace
reg hem pregnow i.curr_method_use $covariates if year==2018, robust
outreg2 using Table_2_1.doc, ci append
logit anemia_dum pregnow i.curr_method_use if year==2018, or robust
outreg2 using Table_2_1.doc, ci eform append
logit anemia_dum pregnow i.curr_method_use $covariates if year==2018, or robust
outreg2 using Table_2_1.doc, ci eform append

*TABLE 4 COL 1: CROSS-SECTIONAL W3 REGRESSION, BROADER CATEGORICAL

reg hem pregnow i.use_hc_ic_no if year==2018, robust
outreg2 using Table_4_1.doc, ci replace
reg hem pregnow i.use_hc_ic_no $covariates if year==2018, robust
outreg2 using Table_4_1.doc, ci append
logit anemia_dum pregnow i.use_hc_ic_no if year==2018, or robust
outreg2 using Table_4_1.doc, ci eform append
logit anemia_dum pregnow i.use_hc_ic_no $covariates if year==2018, or robust
outreg2 using Table_4_1.doc, ci eform append


*SET PANEL
xtset woman_id year

global panel_cov "work own_ag_land bmi tot_children"

*TABLE 2 COLS 2, 3 (HAUSMAN): FE AND RE PANEL REGRESSION
*FE
xtreg hem pregnow i.curr_method_use $panel_cov i.year, fe
estimates store fe1
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_2_2_3.doc, ci replace

*RE
xtreg hem pregnow i.curr_method_use $panel_cov i.year, re
estimates store re1
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_2_2_3.doc, ci append

*Wu-Hausman Test
hausman fe1 re1, sigmamore
*Cannot reject null: random effects model is acceptable.

*FE
xtlogit anemia_dum pregnow i.curr_method_use $panel_cov i.year, fe nolog
estimates store fe2
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_2_2_3.doc, ci eform append

*RE
xtlogit anemia_dum pregnow i.curr_method_use $panel_cov i.year, re nolog
estimates store re2
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_2_2_3.doc, ci eform append

*Wu-Hausman Test
hausman fe2 re2, eq(1:1)
*Cannot reject null: random effects model is acceptable.


*TABLE 4 COLS 2, 3: REGRESSIONS WITH HORMONAL DUMMY VARIABLE
xtreg hem pregnow i.use_hc_ic_no $panel_cov i.year, fe
estimates store fe3
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_4_2_3.doc, ci replace

*RE
xtreg hem pregnow i.use_hc_ic_no $panel_cov i.year, re
estimates store re3
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_4_2_3.doc, ci append

*Wu-Hausman Test
hausman fe3 re3, sigmamore
*Cannot reject null: random effects model is acceptable.

*FE
xtlogit anemia_dum pregnow i.use_hc_ic_no $panel_cov i.year, fe nolog
estimates store fe4
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_4_2_3.doc, ci eform append

*RE
xtlogit anemia_dum pregnow i.use_hc_ic_no $panel_cov i.year, re nolog
estimates store re4
*Joint F-test of whether year dummies are needed
testparm i.year
*Year dummies are needed
outreg2 using Table_4_2_3.doc, ci eform append

*Wu-Hausman Test
hausman fe4 re4, eq(1:1)
*Cannot reject null: random effects model is acceptable.